package module.ahleteView;

import dao.impl.FileDaoImpl;
import util.actionListener.MouseEnterAction;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;

/**
 * @Auther leiHua
 * @Date 2022/5/23 21:47
 */
public class AthleteIndex extends JPanel {
    JButton exeBrowser = new JButton("上一届广软运动会");  //用浏览器打开上一届运动会按钮
    public static String url=null;
    static {
        FileDaoImpl fileDao = new FileDaoImpl();
        url=fileDao .selectIndexUrl();
    }

    AthleteIndex() {
        this.setLayout(null);
        exeBrowser.setFont(new Font("宋体", Font.BOLD, 24));
        exeBrowser.setBounds(400, 700, 250, 50);
        exeBrowser.addMouseListener(new MouseEnterAction(exeBrowser));
        exeBrowser.addActionListener(new ActionListener() {
            //打开网址
            @Override
            public void actionPerformed(ActionEvent e) {
                Runtime rt = Runtime.getRuntime();
                try {
                    FileDaoImpl fileDao = new FileDaoImpl();
                    url=fileDao .selectIndexUrl();
                    rt.exec("rundll32 url.dll,FileProtocolHandler " + url);
                } catch (IOException e1) {
                    e1.printStackTrace();
                }
            }
        });

        ImageIcon imageIcon = new ImageIcon("src/imag/index.jpg");
        imageIcon.setImage(imageIcon.getImage().getScaledInstance(1100,700,1));
        JLabel label = new JLabel();
        label.setIcon(imageIcon);
        label.setBounds(20,0,1100,700);
        this.setBounds(0, 70, 1100, 1000);
        this.add(label);
        this.add(exeBrowser);

    }
}
